package com.sxhuayuan.parking.controller.agent;

import com.sxhuayuan.parking.compenent.Message;
import com.sxhuayuan.parking.compenent.Page;
import com.sxhuayuan.parking.compenent.Pageable;
import com.sxhuayuan.parking.compenent.web.RespMessage;
import com.sxhuayuan.parking.compenent.web.RespMessage.Status;
import com.sxhuayuan.parking.controller.BaseController;
import com.sxhuayuan.parking.entity.Agent;
import com.sxhuayuan.parking.service.AdminService;
import com.sxhuayuan.parking.service.AgentRelationService;
import com.sxhuayuan.parking.service.AgentService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * 代理与子代理
 */
@RestController("agentAgentRelationController")
@RequestMapping("/agent/nexus")
public class AgentRelationController extends BaseController {

	@Resource(name = "agentServiceImpl")
	AgentService agentService;

	@Resource(name = "agentRelationServiceImpl")
	AgentRelationService agentNexusService;

	@Resource(name = "adminServiceImpl")
	AdminService adminService;

	@RequestMapping("/junior/query")
	public RespMessage findJuniorAgentNexus(@RequestBody Pageable pageable, HttpServletRequest request) {

		Agent agent = agentService.getCurrent();

		if (!Objects.isNull(agent)) {
			Page<Agent> page = agentService.findPage(pageable, agent);
			return RespMessage.builder().success().setDatas(page).build();
		} else {
			return invalidToken();
		}
	}
}
